//
//  DealTableViewCell.m
//  BaseFrame
//
//  Created by 孟学浩 on 2017/5/11.
//  Copyright © 2017年 com.mxh. All rights reserved.
//

#import "DealTableViewCell.h"

@interface DealTableViewCell()

@property (nonatomic,strong) UIImageView *imgView;
@property (nonatomic,strong) UILabel *infoLabel;
@property (nonatomic,strong) UILabel *timeLabel;
@property (nonatomic,strong) UIButton *deleteBtn;

@end

@implementation DealTableViewCell

- (instancetype)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier{
    if (self = [super initWithStyle:style reuseIdentifier:reuseIdentifier]) {
        self.selectionStyle = 0;
        
        _imgView = [UIImageView new];
        _imgView.backgroundColor = getColor(@"f1f2f6");
        _imgView.contentMode = UIViewContentModeScaleAspectFit;
        
        _infoLabel = [UILabel new];
        _infoLabel.numberOfLines = 0;
        _infoLabel.font = DEF_FontSize_12;
    
        _timeLabel = [UILabel new];
        _timeLabel.numberOfLines = 0;
        _timeLabel.font = DEF_FontSize_12;
        _timeLabel.textAlignment = NSTextAlignmentRight;
        
        _deleteBtn = [UIButton new];
        [_deleteBtn setTitle:@"删除" forState:UIControlStateNormal];
        _deleteBtn.titleLabel.font = DEF_FontSize_10;
        [_deleteBtn setTitleColor:getColor(mainColor) forState:UIControlStateNormal];
        _deleteBtn.layer.masksToBounds = YES;
        _deleteBtn.layer.cornerRadius = 3;
        _deleteBtn.layer.borderColor = getColor(mainColor).CGColor;
        _deleteBtn.layer.borderWidth = .5;
        
        [self.contentView addSubview:_imgView];
        [self.contentView addSubview:_infoLabel];
        [self.contentView addSubview:_timeLabel];
        [self.contentView addSubview:_deleteBtn];

    }
    return self;
}

- (void)layoutSubviews{
    [super layoutSubviews];
    _imgView.frame = CGRectMake(12, 0, self.frame.size.height-15, self.frame.size.height-15);
    _imgView.center = CGPointMake(_imgView.center.x, self.frame.size.height/2.);
    
    _infoLabel.frame = CGRectMake(CGRectGetMaxX(_imgView.frame)+10, 0, SCREEN_WIDTH - CGRectGetMaxX(_imgView.frame) - 20, self.frame.size.height);
    _timeLabel.frame = CGRectMake(CGRectGetMaxX(_imgView.frame)+10, 5, SCREEN_WIDTH - CGRectGetMaxX(_imgView.frame) - 20, 45);
    _deleteBtn.frame = CGRectMake(self.width-58, self.height-22, 42, 16);
}

- (void)setDataDictionary:(NSDictionary *)dataDictionary{
    _dataDictionary = dataDictionary;
    
    NSString *shopName = @"店铺名字";
    NSString *price = @"500";
    NSString *count = @"2";
    NSString *info = @"大保健套装";
    NSString *orderId = @"25345241124";
    NSString *countPrice = [NSString stringWithFormat:@"¥%@",@"1000"];
    NSString *time = @"2017-05-10";

    NSString *infoString = [NSString stringWithFormat:@"%@\n单价 ¥%@ / 数量 %@\n%@\n单号 %@",shopName,price,count,info,orderId];
    NSString *timeString = [NSString stringWithFormat:@"累计 %@\n%@",countPrice,time];
//
    NSMutableAttributedString *attStr = [[NSMutableAttributedString alloc] initWithString:infoString];
    NSMutableParagraphStyle *paragraphStyle = [[NSMutableParagraphStyle alloc] init];
    [paragraphStyle setLineSpacing:3];//调整行间距
    [attStr addAttribute:NSParagraphStyleAttributeName value:paragraphStyle range:NSMakeRange(0, [infoString length])];
    [attStr addAttribute:NSFontAttributeName value:[UIFont systemFontOfSize:12 weight:1] range:[infoString rangeOfString:shopName]];
//
    NSMutableAttributedString *attStr1 = [[NSMutableAttributedString alloc] initWithString:timeString];
    NSMutableParagraphStyle *paragraphStyle1 = [[NSMutableParagraphStyle alloc] init];
    [paragraphStyle1 setLineSpacing:8];//调整行间距
    [paragraphStyle1 setAlignment:NSTextAlignmentRight];
    [attStr1 addAttribute:NSParagraphStyleAttributeName value:paragraphStyle1 range:NSMakeRange(0, [timeString length])];
    [attStr1 addAttribute:NSForegroundColorAttributeName value:getColor(mainColor) range:[timeString rangeOfString:countPrice]];
//
    _infoLabel.attributedText = attStr;
    _timeLabel.attributedText = attStr1;
}

@end
